package cn.ekgc.hbase.phoenix;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class SelectAll {
    public static void main(String[] args) throws Exception {
        Connection connection = DriverManager.getConnection("jdbc:phoenix:hadoop-zoo1,hadoop-zoo2,hadoop-zoo3",new Properties());
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT state as \"State\",count(city) as \"City Count\",sum(population) as \"Population Sum\"\n" +
                "FROM us_population\n" +
                "GROUP BY state\n" +
                "ORDER BY sum(population) DESC");
        while (resultSet.next()){
            System.out.println(resultSet.getString("State")+"\t"+resultSet.getInt("City Count")+"\t"+resultSet.getLong("Population Sum"));
        }
        connection.close();

    }
}
